<template>
  <div class="wrapper swiper-no-swiping">
    <swiper :options="swiperOption"  v-if="showSwiper">
      <!-- slides -->
      <swiper-slide  v-for="item of swiperlist" :key="item.id">
        <a :href="item.href">
          <img class="swiper_img" :src="item.imgUrl" />
        </a>
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
      <div  class = "swiper-button-prev"  slot = "button-prev" > </div >
      <div  class = "swiper-button-next"  slot = "button-next" > </div >
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    swiperlist: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        paginationBulletRender: function (swiper, index, className) {
          return '<span class="' + className + '">' + (index + 1) + '</span>'
        },
        prevButton: '.swiper-button-prev',
        nextButton: '.swiper-button-next',
        autoplay: 3000,
        autoplayDisableOnInteraction: false
      }
    }
  },
  computed: {
    showSwiper () {
      return this.swiperlist.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet
    opacity .5!important
    width 20px
    height 20px
    line-height 20px
    color white!important
  .wrapper >>> .swiper-pagination-bullet-active
    background: white!important
    opacity 1!important
    width 20px
    height 20px
    line-height 20px
    color red!important
  .wrapper >>> .swiper-container-horizontal > .swiper-pagination-bullets
    bottom: 0.16rem
  .wrapper
    width 100%
    height 0
    padding-bottom 56.2%
    margin-top .3rem
    overflow hidden
    background #eee
    .swiper_img
      width 100%
</style>
